#include <stdio.h>

#define AGE(left, right) (((left) + (right)) / 2)

int bisearch (int a[], int n, int x) {
    int left = 0;
    int right = n;
    while (left < right) {
        if (a[AGE(left, right)] < x) {
            left = AGE(left, right);
        } else if (a[AGE(left, right)] > x) {
            right = AGE(left, right);
        } else if (a[AGE(left, right)] == x) {
            return AGE(left, right);
        }
    }
    return -1;
}

int main()
{
    int arr1 [1] = {1};
    int arr[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
    int n = bisearch(arr, 11, 7);
    printf("%d", n);
    return 0;
}